package com.weita.lightfood.service;


import com.weita.lightfood.model.dao.MaterialDao;
import com.weita.lightfood.model.entity.Material;
import com.weita.lightfood.model.vo.material.AddDishMaterialVo;
import com.weita.lightfood.model.vo.material.MaterialAttributeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author IT_Monster at 2019/03/31 13:29.
 * 食材服务
 */
@Service
public class MaterialService {
    @Autowired
    MaterialDao materialDao;

    /**
     * 添加食材
     * @param material
     * @return
     */
    public Material addMaterial(Material material) throws Exception {
        materialDao.addMaterial(material);
        return material;
    }

    /**
     * 获取通过菜谱id食材
     * @param dishId
     * @return
     */
    public List<MaterialAttributeVo> getMaterial(int dishId) throws Exception {
        return materialDao.getMaterial(dishId);
    }

    /**
     * 获取所有肉类谷物坚果食材0
     * @return
     */
    public List<AddDishMaterialVo> getAllMeats() throws Exception {
        return materialDao.getTypeMaterial(0);
    }

    /**
     * 获取蔬菜水果类食材1
     * @return
     */
    public List<AddDishMaterialVo> getAllVegetables() throws Exception {
        return materialDao.getTypeMaterial(1);
    }


    /**
     * 获取佐料类食材2
     * @return
     */
    public List<AddDishMaterialVo> getAllSeasoning() throws Exception {
        return materialDao.getTypeMaterial(2);
    }


    /**
     * 通过食材名获取食材id
     * @param name
     * @return
     */
    public int getIdByMaterialName(String name) throws Exception {
        int result = materialDao.getIdByMaterialName(name);
        return result;
    }



    /**
     * 获取精选食材名到用户端
     * @return
     */
    public List<String> getChoicenessMaterialName() throws Exception {
        return materialDao.getChoicenessMaterialName();
    }


    /**
     * 通过食材名获取食材热量
     * @param name
     * @return
     */
    public String getCalorieByMaterialName(String name){
        try {
          return  "" + materialDao.getCalorieByMaterialName(name);
        } catch (Exception e) {
            return "该食材不存在";
        }
    }

    public List<Integer> getMaterialIdByChoicenessName (String materialName) throws Exception {
        return materialDao.getMaterialIdByChoicenessName(materialName);
    }


}
